#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QEvent>
#include <QDebug>
#include <QKeyEvent>

class Item
{
public:
    Item(Item *parent=NULL, QString title="", QString data="",Item *l=NULL, Item *u=NULL): data(data),
         title(title)
    {
        if(parent == NULL)
            return ;
        this->parent = parent;
        if(parent->child == NULL)
        {
            parent->child = this;
            //left = parent->left;
            //right = parent->right;
        }

        if(l != NULL && l->right == NULL)
        {
            left = l;
            if(l->right == NULL)
                l->right = this;
        }
        if(u != NULL)
        {
            up = u;
            u->down = this;
            isListView = true;
        }
    }
    void setDown(Item *d)
    {
        down = d;
        d->up = this;
        d->isListView = true;
    }

    void setLeft(Item *l)
    {
        left = l;
        l->right = this;
    }

    void setRight(Item *r)
    {
        right = r;
        r->left = this;
    }

    bool isListView = false;  //列表显示
    bool isFocus = false;
    QString title;

    QString data = "";
    Item* left = NULL;
    Item* right = NULL;
    Item* up = NULL;
    Item* down = NULL;
    Item* child = NULL;
    Item *parent = NULL;
};

class Widget : public QWidget
{
    Q_OBJECT
public:
    explicit Widget(QObject *parent = nullptr);

    void keyPressEvent(QKeyEvent *event)override;
    Item *root;
    Item *currentItem = NULL;

    QObject *obj;
    void updateMenu();
    void updateFocus(Item *, Item *);
    void setObject(QObject *);
signals:
    void sigList(QVariantList);
};

#endif // WIDGET_H
